
let app = getApp();

  
//Page Object
Page({
  data: {
    latitude:0,
    longitude:0,
    markers:[],
    currentAddress:'', // 详细地址
    province:''  // 省市区
  },
  //options(Object)
  onLoad: function(options) {
    
  },

  onShow: function() {
    const _that = this;
    wx.getLocation({
      type: 'gcj02',
      altitude: false,//获取高度信息
      success: (result) => {
        console.log(result)
        // 修改经纬度的值
        _that.setData({
          latitude:result.latitude,
          longitude:result.longitude,
        })

        // console.log(app.globalData.qqmapsdk)
        // 根据经纬度获取当前的文字地址描述
        app.globalData.qqmapsdk.reverseGeocoder({
          location:{
            longitude:result.longitude,
            latitude:result.latitude
          },
          coord_type:5,
          success:(res)=>{
            // console.log("看看返回的是什么地市",res);
            const address = res.result.formatted_addresses.recommend;
            const {province,city,district} = res.result.address_component
            if(res.status === 0){
              _that.setData({
                currentAddress:address,
                province:province+city+district
              });
              app.globalData.currentAddress = address;
              app.globalData.province = province+city+district
            }
          },
          fail: (err) => {
            // console.log(err)
          },
        })
      },
      fail: (err) => {
        // console.log('getLocation错误',err)
      }
    });
      
  },

  //得到经纬度
  getLongitudeLatitude(res){
    console.log('点击得到经纬度',res.detail);
    const _that = this;
    const result = res.detail;
    // 根据经纬度获取当前的文字地址描述

    app.globalData.qqmapsdk.reverseGeocoder({
      location:{
        longitude:result.longitude,
        latitude:result.latitude
      },
      coord_type:5,
      success:(res)=>{
        // console.log("看看返回",res);

        const address = res.result.formatted_addresses.recommend;
        if(res.status === 0){
          _that.setData({
            currentAddress:address,
            markers:[{
              latitude:result.latitude,
              longitude:result.longitude,
              iconPath:'../../image/icon/position.png',
              width:10,
              height:30
            }]
          });
          app.globalData.currentAddress = address
        }
      },
      fail: (err) => {
        // console.log(err)
      },
    })
  }
});
  